<template>
<div class="mod-config">
    <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="上架管理" name="checkApplication">
            <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
                <el-form-item label="申请人">
                    <el-input v-model="dataForm.key" clearable></el-input>
                </el-form-item>
                        <el-form-item label="申请状态" prop="status">
            <el-select v-model="dataForm.status" placeholder="请选择">
                <el-option v-for="item in statusList" :key="item.id" :label="item.desc" :value="item.id"></el-option>
            </el-select>
        </el-form-item>
                <el-form-item>
                    <el-button @click="getDataList()">查询</el-button>
                    <el-button v-if="isAuth('generator:tborrow:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
                    <el-button v-if="isAuth('generator:tborrow:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
                </el-form-item>
            </el-form>
            <el-table :data="dataList" border v-loading="dataListLoading" style="width: 100%;">
                <el-table-column prop="applyDate" header-align="center" align="center" label="申请时间">
                    <template slot-scope="scope">{{scope.row.applyDate | formatDate}}</template>
                </el-table-column>
                <el-table-column prop="applicant" header-align="center" align="center" label="申请人"></el-table-column>
                <el-table-column prop="bookListStr" header-align="center" label="申请图书"></el-table-column>
                <el-table-column header-align="center" align="center" label="申请状态">
                    <template slot-scope="scope">
                        <span v-if="scope.row.status==1">待审核</span>
                        <span v-if="scope.row.status==2">待出库</span>
                        <span v-if="scope.row.status==3">待上架</span>
                        <span v-if="scope.row.status==4">已上架</span>
                    </template>
                </el-table-column>
                <el-table-column prop="note" header-align="center" align="center" label="备注"></el-table-column>
                <el-table-column header-align="center" align="center" width="150" label="操作">
                    <template slot-scope="scope">
                        <el-button v-if="scope.row.status==1" type="text" size="small" @click="check(scope.row)">审核</el-button>
                        <el-button v-if="scope.row.status==3" type="text" size="small" @click="up(scope.row.id)">上架</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
            <t-putaway-check v-if="checkVisible" ref="tPutawayCheck" @refreshDataList="getDataList"></t-putaway-check>
            <t-up v-if="upVisible" ref="tUp" @refreshDataList="getDataList"></t-up>
        </el-tab-pane>
        <el-tab-pane label="借书管理" name="second">
            <t-borrow ref="tBorrow" @refreshDataList="getDataList"></t-borrow>
        </el-tab-pane>
        <el-tab-pane label="续借管理" name="third">
            <t-renew ref="tRew"></t-renew>
        </el-tab-pane>
        <el-tab-pane label="归还管理" name="fourth">
            <t-back ref="tBack"></t-back>
        </el-tab-pane>
    </el-tabs>
</div>
</template>

<script>
import TPutawayCheck from "./tputaway-check";
import TUp from "./tup";
import TBorrow from "./tborrow";
import TRenew from "./trenew";
import TBack from "./tback";
export default {
    data() {
        return {
            statusList: [{
                id: 1,
                desc: "待审核"
            }],
            activeName: "checkApplication",
            dataForm: {},
            dataList: [],
            pageIndex: 1,
            pageSize: 10,
            totalPage: 0,
            dataListLoading: false,
            checkVisible: false,
            upVisible: false
        };
    },
    components: {
        TPutawayCheck,
        TUp,
        TBorrow,
        TRenew,
        TBack
    },
    activated() {
        this.getDataList();
    },
    methods: {
        handleClick(tab, event) {},
        // 获取待审核数据列表
        getDataList() {
            this.dataListLoading = true;
            this.$http({
                url: this.$http.adornUrl("/generator/tputwayapplication/list"),
                method: "get",
                params: this.$http.adornParams({
                    page: this.pageIndex,
                    limit: this.pageSize,
                    status: 1,
                }),
            }).then(({
                data
            }) => {
                if (data && data.code === 0) {
                    this.dataList = data.page.list;
                    this.dataList.forEach(function (item) {
                        let bookListStr = "";
                        item.bookList.forEach(function (i) {
                            bookListStr += i.name + ",";
                        });
                        item.bookListStr = bookListStr.substr(0, bookListStr.length - 1);
                    });
                    this.totalPage = data.page.totalCount;
                } else {
                    this.dataList = [];
                    this.totalPage = 0;
                }
                this.dataListLoading = false;
            });
        },
        // 每页数
        sizeChangeHandle(val) {
            this.pageSize = val;
            this.pageIndex = 1;
            this.getDataList();
        },
        // 当前页
        currentChangeHandle(val) {
            this.pageIndex = val;
            this.getDataList();
        },
        // 审核
        check(row) {
            this.checkVisible = true;
            this.$nextTick(() => {
                this.$refs.tPutawayCheck.init(row);
            });
        },
        // 上架
        up(row) {
            this.upVisible = true;
            this.$nextTick(() => {
                this.$refs.tUp.init(row);
            });
        }
    },
};
</script>
